import { supportHtmlWebpackPlugin, pluginHandle } from './supportPlugin'
import { originalHandle } from './original'
import { Compiler } from 'webpack'

const pluginName = 'HtmlResourceManagerPlugin'

module.exports = class HtmlResourceManagerPlugin {

  constructor() { }

  public apply(compiler: Compiler) {
    if (!compiler.hooks) { return }

    const support = supportHtmlWebpackPlugin()

    if (support) {
      compiler.hooks.compilation.tap(pluginName, compilation => {
        pluginHandle(pluginName, compilation)
      })
    } else {
      compiler.hooks.done.tap(pluginName, stats => {
        originalHandle(compiler)
      })
    }
  }
}